package com.ruoyi.web.controller.shelves;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.shelves.domain.Mtype;
import com.ruoyi.shelves.service.IMtypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 工具类型表Controller
 *
 * @author tongshuai
 * @date 2021-12-02
 */
@RestController
@RequestMapping("/mtype/mtype")
public class MtypeController extends BaseController
{
    @Autowired
    private IMtypeService mtypeService;

    /**
     * 查询工具类型表列表
     */
    @PreAuthorize("@ss.hasPermi('mtype:mtype:list')")
    @GetMapping("/list")
    public TableDataInfo list(Mtype mtype)
    {
        startPage();
        List<Mtype> list = mtypeService.selectMtypeList(mtype);
        return getDataTable(list);
    }

    /**
     * 导出工具类型表列表
     */
    @PreAuthorize("@ss.hasPermi('mtype:mtype:export')")
    @Log(title = "工具类型表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Mtype mtype)
    {
        List<Mtype> list = mtypeService.selectMtypeList(mtype);
        ExcelUtil<Mtype> util = new ExcelUtil<Mtype>(Mtype.class);
        util.exportExcel(response, list, "工具类型表数据");
    }

    /**
     * 获取工具类型表详细信息
     */
    @PreAuthorize("@ss.hasPermi('mtype:mtype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mtypeService.selectMtypeById(id));
    }

    /**
     * 新增工具类型表
     */
    @PreAuthorize("@ss.hasPermi('mtype:mtype:add')")
    @Log(title = "工具类型表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Mtype mtype)
    {
        return toAjax(mtypeService.insertMtype(mtype));
    }

    /**
     * 修改工具类型表
     */
    @PreAuthorize("@ss.hasPermi('mtype:mtype:edit')")
    @Log(title = "工具类型表", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody Mtype mtype)
    {
        return toAjax(mtypeService.updateMtype(mtype));
    }

    /**
     * 删除工具类型表
     */
    @PreAuthorize("@ss.hasPermi('mtype:mtype:remove')")
    @Log(title = "工具类型表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mtypeService.deleteMtypeByIds(ids));
    }
}
